package com.projectzqjz.parttimework.base;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.FragmentActivity;
import android.view.WindowManager;

import com.projectzqjz.parttimework.utils.StatusBarUtil;

import butterknife.ButterKnife;

public abstract class BaseActivity extends FragmentActivity {


    @RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //禁止横竖屏切换
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        //设置状态栏全透明
        setStatusBar();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        //设置布局
        setContentView(intiLayout());
        //绑定组件
        ButterKnife.bind(this);
        //设置状态栏颜色,以及是否为全屏
        setTitleBarColor();
        //初始化控件
        initView();
        //添加监听
        setListen();
        //设置数据
        initData();
    }

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onSaveInstanceState(Bundle outState) {
//        super.onSaveInstanceState(outState);
    }
    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    public abstract void setListen();

    /**
     * 设置状态栏颜色
     */
    public abstract void setTitleBarColor();

    /**
     * 设置布局
     *
     * @return id
     */
    public abstract int intiLayout();

    /**
     * 初始化布局
     */
    public abstract void initView();

    /**
     * 设置数据
     */
    public abstract void initData();

    /**
     * 默认状态栏 字体都是黑的
     * 需要的时候 返回 true 字体变成白色的
     *
     * @return boolean
     */
    protected boolean isStatusBarBlack() {
        return false;
    }

    /**
     * 设置透明状态栏
     */
    private void setStatusBar() {
        StatusBarUtil.setStatusBar(this, isStatusBarBlack());
    }
}
